package com.yxj03;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapDemo {
    public static void main(String[] args) {
        HashMap<String ,Student> hm = new HashMap<String,Student>();
        Student s1 = new Student("米",23);
        Student s2 = new Student("鸡窝",22);
        Student s3 = new Student("自由", 4);
        hm.put("A0001",s1);
        hm.put("A0002",s2);
        hm.put("A0003", s3);
        //方法1：键找值
        Set<String> keySet = hm.keySet();
        for(String key : keySet) {
            Student value = hm.get(key);
            System.out.println(key+","+value.getName()+","+value.getAge());
        }
        System.out.println("----------");
        //方法2：键值对对象找键和值
        Set<Map.Entry<String,Student>> entrySet = hm.entrySet();
        for(Map.Entry<String,Student> me : entrySet) {
            String key = me.getKey();
            Student value = me.getValue();
            System.out.println(key+","+value.getName()+","+value.getAge());
        }
    }
}
